package com.shujia.kafka

import java.util
import java.util.Properties

import org.apache.kafka.clients.consumer.KafkaConsumer

object Demo3Consumer {

  def main(args: Array[String]): Unit = {

    val properties = new Properties()

    properties.setProperty("bootstrap.servers","master:9092,node1:9092,node2:9092")

    properties.setProperty("key.serializer","org.apache.kafka.common.serialization.StringSerializer")
    properties.setProperty("value.serializer","org.apache.kafka.common.serialization.StringSerializer")

    properties.setProperty("group.id","asssad")

    //是否自动提交消费偏移量
    properties.setProperty("enable.auto.commit","false")

    //自动提交偏移量
    //如果间隔时间太短会影响性能
    properties.put("auto.commit.interval.ms","1000")

    /**
      *
      */

    //从最早读取数据
    properties.put("auto.offset.reset","earliest")

    //创建消费者
    val consumer: KafkaConsumer[String, String] = new KafkaConsumer[String,String](properties)

    val topics: util.ArrayList[String] = new util.ArrayList[String]()

    topics.add("student")
    //订阅topic

  }

}
